﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace DMSkin.WeChat.Controls
{
    public class IconButton : Button
    {
        public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(IconButton), new PropertyMetadata(null));

        /// <summary>
        /// 圆角边
        /// </summary>
        [Description("圆角边"), Category("DMSkin")]
        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }

        public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(Geometry), typeof(IconButton), new PropertyMetadata(null));

        /// <summary>
        /// 图标
        /// </summary>
        [Description("图标"), Category("DMSkin")]
        public Geometry Icon
        {
            get { return (Geometry)GetValue(IconProperty); }
            set { SetValue(IconProperty, value); }
        }

        public static readonly DependencyProperty IconWidthProperty = DependencyProperty.Register("IconWidth", typeof(double), typeof(IconButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标宽度
        /// </summary>
        public double IconWidth
        {
            get { return (double)GetValue(IconWidthProperty); }
            set { SetValue(IconWidthProperty, value); }
        }

        public static readonly DependencyProperty IconHeightProperty = DependencyProperty.Register("IconHeight", typeof(double), typeof(IconButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标高度
        /// </summary>
        public double IconHeight
        {
            get { return (double)GetValue(IconHeightProperty); }
            set { SetValue(IconHeightProperty, value); }
        }

        public static readonly DependencyProperty IconForegroundProperty = DependencyProperty.Register("IconForeground", typeof(Brush),
        typeof(IconButton), new PropertyMetadata(Brushes.Gray, OnPropertyChanged));

        /// <summary>
        /// 图片颜色
        /// </summary>
        public Brush IconForeground
        {
            set { SetValue(IconForegroundProperty, value); }
            get { return (Brush)GetValue(IconForegroundProperty); }
        }

        public static readonly DependencyProperty IconBackgroundProperty = DependencyProperty.Register("IconBackground", typeof(Brush),
        typeof(IconButton), new PropertyMetadata(Brushes.Gray, OnPropertyChanged));

        /// <summary>
        /// 图片颜色
        /// </summary>
        public Brush IconBackground
        {
            set { SetValue(IconBackgroundProperty, value); }
            get { return (Brush)GetValue(IconBackgroundProperty); }
        }

        private static void OnPropertyChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs args)
        {
            IconButton button = dependency as IconButton;
            if (args.Property.Name.Equals("IconForeground"))
                button.IconForeground = (Brush)args.NewValue;
            if (args.Property.Name.Equals("IconBackground"))
                button.IconBackground = (Brush)args.NewValue;
        }
    }
}
